package com.xiqi.microservice.zuul.handler;

import com.xiqi.microservice.zuul.bean.BaseResultBean;
import com.xiqi.microservice.zuul.exception.MyIllegalAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @program: apigateway
 * @description:
 * @author: Shine
 * @create: 2019-08-01 15:11
 */
@ResponseBody
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * @Author: Shine
     * @Date: 19-8-1 下午3:16
     * @Description: 没有权限异常
     * @Param: [exception]
     * @return: com.xiqi.microservice.zuul.bean.BaseResultBean
     */
    @ExceptionHandler(MyIllegalAccessException.class)
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    public BaseResultBean handlerMyException(MyIllegalAccessException exception){
        //todo：忘记给BaseResultBean写静态的赋值方法了
        BaseResultBean bean = new BaseResultBean();
        bean.setCode(401);
        bean.setMessage("没有访问权限");
        return bean;
    }
}
